#ifndef RTP_PARSER_H264PARSER_H
#define RTP_PARSER_H264PARSER_H

#include <iostream>
#include "NetworkProtocolParser.h"
#include "FrameCache.h"

typedef struct {
    uint8_t f : 1;
    uint8_t nri : 2;
    uint8_t type : 5;
} nalu_header;

typedef struct {
    uint8_t s : 1;
    uint8_t e : 1;
    uint8_t r : 1;
    uint8_t type : 5;
} fu_a_header;

class H264parser {
public:
	static unsigned int ShowU8(const unsigned char* pBuf) { return  pBuf[0]; }
	static unsigned int ShowU16(const unsigned char* pBuf) { return  (pBuf[0] << 8) | (pBuf[1]); }
	static unsigned int ShowU24(const unsigned char* pBuf) { return  (pBuf[0] << 16) | (pBuf[1] << 8) | (pBuf[2]); }
	static unsigned int ShowU32(const unsigned char* pBuf) { return  (pBuf[0] << 24)  | (pBuf[1]<<16); }

    static H264parser *get_instance();
    static void release();
    void parse(const rtp_info &rtpInfo, const unsigned char *data, size_t size);
private:
    H264parser() = default;
    static H264parser *instance;
    FrameCache cache;
};


#endif //RTP_PARSER_H264PARSER_H
